<?php
class Plan_Service_PlanRates
{
	protected $_modelPlan = null;
	protected $_modelPlanUsage = null;
	protected $_modelPlanRates = null;
	protected $_modelPlanUsageDetail = null;
	
	//初始化
	public function __construct(){
		$this->_modelPlan = new Plan_Model_Plan();
		$this->_modelPlanUsage = new Plan_Model_PlanUsage();
		$this->_modelPlanRates = new Plan_Model_PlanRates();
	}
	
	public function add($row){
		return $this->_modelPlanRates->add($row);
	}
	
	public function update($row,$id){
		return $this->_modelPlanRates->update($row,$id);
	}
	
	public function getById($id){
		return $this->_modelPlanRates->getById($id);
	}
	
	public function delete($id){
		return $this->_modelPlanRates->delete($id);
	}
		
    public function getByCondition($condition,$type='*',$orderby="",$page=0,$pageSize=0){
        return $this->_modelPlanRates->getByCondition($condition,$type,$orderby,$page,$pageSize);
	}

    public function validator($val) {
        $error = array();
        $validateArr = array();
        $validateArr[] = array('name' => '计费类型', 'value' => $val['type'], 'regex' => array('require', 'length[0,255]', ));
		$validateArr[] = array('name' => '货币CODE', 'value' => $val['currency_code'], 'regex' => array('require', 'length[0,255]', ));
		$validateArr[] = array('name' => '标准价格', 'value' => $val['price'], 'regex' => array('require', 'number[0,999999999]', ));
		$validateArr[] = array('name' => '折扣', 'value' => $val['discount'], 'regex' => array('require', 'number[0,999999999]', ));
		$validateArr[] = array('name' => '区间开始', 'value' => $val['range_start'], 'regex' => array('require', 'number[0,999999999]', ));
		$validateArr[] = array('name' => '区间结束', 'value' => $val['range_end'], 'regex' => array('require', 'number[0,999999999]', ));
		$validateArr[] = array('name' => '排序', 'value' => $val['order'], 'regex' => array('number[0,99999]', ));
        $error = Common_Service_Validator::formValidator($validateArr);
		if($val['range_end']-$val['range_start']<0){
			$error[]="区间开始的值不能大于区间结束的值!";
		}
        return $error;
    }
	
}